package me.leiusual.sharing.api.cookie

import okhttp3.Cookie
import okhttp3.CookieJar
import okhttp3.HttpUrl
import java.util.concurrent.ConcurrentHashMap

/**
 * Create by leiusual on 2018/7/22
 */
class CookieJarImpl : CookieJar {

  companion object {
    private val cookiesMap = ConcurrentHashMap<String, List<Cookie>>()
  }

  override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
    cookiesMap[url.host()] = cookies
  }

  override fun loadForRequest(url: HttpUrl): List<Cookie> {
    return cookiesMap[url.host()] ?: arrayListOf()
  }
}